package icu.sehnen.servlet;

import icu.sehnen.model.CoachModel;
import icu.sehnen.model.CompanyModel;
import icu.sehnen.model.NavModel;
import icu.sehnen.model.NewsModel;
import icu.sehnen.service.CoachService;
import icu.sehnen.service.CompanyService;
import icu.sehnen.service.NavService;
import icu.sehnen.service.NewsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


@WebServlet("/home")
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        响应到某个具体的页面

        CompanyService companyService=new CompanyService();
        CompanyModel companyModel=companyService.getCompannModelForHome();
        req.setAttribute("companyModel",companyModel);

//        三行代码
        NavService navService=new NavService();
        List<NavModel> navModelList=navService.getNavModelListForHome();
        req.setAttribute("navModelList",navModelList);


//       教练信息
        CoachService coachService=new CoachService();
        List<CoachModel> coachModelList=coachService.getCoachModelForHome();
        req.setAttribute("coachModelList",coachModelList);



//       新闻信息
        NewsService newsService=new NewsService();
        List<NewsModel> newsModelList=newsService.getNewsModelForHome();
        req.setAttribute("newsModelList",newsModelList);
        req.getRequestDispatcher("/jsp/home.jsp").forward(req,resp);
    }
}
